package cn.com.surker.material.service.impl;

import cn.com.surker.material.entity.MainMaterialInventory;
import cn.com.surker.material.dao.MainMaterialInventoryDao;
import cn.com.surker.material.service.MainMaterialInventoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import cn.com.surker.spring.RestResultDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
* <p>
    * 材料盘存汇总表 服务实现类
    * </p>
*
* @author admin
* @since 2024-12-05
*/
@Service
public class MainMaterialInventoryServiceImpl extends ServiceImpl<MainMaterialInventoryDao, MainMaterialInventory> implements MainMaterialInventoryService {

        @Resource
        private MainMaterialInventoryDao mapper;


        /**
        * 根据条件查询所有的数据
        * @param dto
        * @return
        */
        public RestResultDto findAll(MainMaterialInventory dto){

            QueryWrapper<MainMaterialInventory> query = new QueryWrapper();
            query.setEntity(dto);
            List<MainMaterialInventory> list = mapper.selectList(query);

            return RestResultDto.success(list);
        }


        /**
        * 分页查询数据
        * @param dto page
        * @return
        */
        public RestResultDto findAllByPage(MainMaterialInventory dto, Page<MainMaterialInventory> page){
            QueryWrapper<MainMaterialInventory> query = new QueryWrapper();
            query.setEntity(dto);
            IPage<MainMaterialInventory> iPage = mapper.selectPage(page,query);

            return RestResultDto.success(iPage);
        }


        /**
        * 新增数据
        * @param dto page
        * @return
        */
        public RestResultDto saveInit(MainMaterialInventory dto){
            int saveStatus = mapper.insert(dto);
            if(saveStatus > 0){
                return RestResultDto.success("保存成功!");
            }else{
                return RestResultDto.success("保存失败!");
            }

        }

        /**
        * 更新数据
        * @param dto page
        * @return
        */
        public RestResultDto update(MainMaterialInventory dto){

            int saveStatus = mapper.updateById(dto);
            if(saveStatus > 0){
                return RestResultDto.success("保存成功!");
            }else{
                return RestResultDto.success("保存失败!");
            }

        }
}